(function() {
    var nilaiDollarApi = "http://nilaidollar.appspot.com/currenciesAll.go";
    var data = [{bankCode: 'BI', bankName: 'Bank Indonesia', dollarJual: '11.928.23', dollarBeli: '9,231.23', lastUpdated: '17-Jan-2014'},
        {bankCode: 'BCA', bankName: 'Bank Central Asia', dollarJual: '11.928.23', dollarBeli: '9,231.23', lastUpdated: '17-Jan-2014'},
        {bankCode: 'BNI', bankName: 'Bank Negara Indonesia', dollarJual: '11.928.23', dollarBeli: '9,231.23', lastUpdated: '17-Jan-2014'},
        {bankCode: 'Mandiri', bankName: 'Bank Mandiri', dollarJual: '11.928.23', dollarBeli: '9,231.23', lastUpdated: '17-Jan-2014'}];

    function formatCurrency(n, currency) {
        return n.toFixed(2).replace(/./g, function(c, i, a) {
            return i > 0 && c !== "." && (a.length - i) % 3 === 0 ? "," + c : c;
        });
    }
    
    function convertToAed(usd){
        return usd / 3.68;
    }
    
    $.getJSON(nilaiDollarApi, {}).done(function(data) {
        $.each(data, function(i, currency) {
            var template = '<tr><td>' + currency.bankCode + '<br><small style="font-size:0.7em">' + currency.lastUpdate + '</small>  </td><td>' + formatCurrency(currency.dollarBeli,'') + '</td><td>' + formatCurrency(currency.dollarJual,'') + '</td><td>' + formatCurrency(convertToAed(currency.dollarBeli),'') + '</td><td>' + formatCurrency(convertToAed(currency.dollarJual),'') + '</td></tr>';
            $('#tableBody').append(template);
        });
    });
})();


